package com.kchouse.homepage;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.kchouse.R;
import com.kchouse.common.BaseActivity;
import com.kchouse.mine.MineprestoreActivity;
import com.kchouse.mine.OrderActivity;

public class PayResultsActivity extends BaseActivity implements View.OnClickListener {

    private PayResultsActivity mContent;
    private TextView tv_title;
    private ImageView iv_back;
    private Intent intent;
    private String ordertype;
    private Button bt_order;
    private String Order;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_results);


        Intent mIntent = new Intent("refresh");
        //发送广播
        sendBroadcast(mIntent);
        mContent = this;
        intiData();
        intiView();
    }

    private void intiData() {
        intent = getIntent();
        Order = intent.getStringExtra("Order");
    }

    private void intiView() {
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_title.setText("支付成功");
        iv_back = (ImageView) findViewById(R.id.iv_back);
        iv_back.setOnClickListener(this);

        bt_order = (Button) findViewById(R.id.bt_order);

        switch (Order){

            case "1":
                bt_order.setText("查看我的订单");
                break;
            case "2":
                bt_order.setText("查看我的预存");
                break;
            case "3":
                bt_order.setText("查看我的订单");
                break;
        }
//        if (Order.equals("1")) {
//            bt_order.setText("查看我的订单");
//        } else {
//            bt_order.setText("查看我的预存");
//        }
        bt_order.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                clearAct();
                finish();
                break;
            case R.id.bt_order:
                clearAct();

                switch (Order){
                    case "1":
                        intent.putExtra("ordertype", "全部订单");
                        intent.setClass(mContent, OrderActivity.class);
                        startActivity(intent);
                        break;
                    case "2":
                        intent.setClass(mContent, MineprestoreActivity.class);
                        startActivity(intent);
                        break;
                    case "3":
//                        finish();
                        break;
                }

//                if (!Order.equals("1")) {
//                    intent.setClass(mContent, MineprestoreActivity.class);
//                    startActivity(intent);
//                } else {
//                    intent.putExtra("ordertype", "全部订单");
//                    intent.setClass(mContent, OrderActivity.class);
//                    startActivity(intent);
//                }
                finish();
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            clearAct();
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
